package com.zpark.drug.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author Daimingdong
 * @version 1.0.0
 * @title MyWebConfig
 * @create 2024/6/11 19:46
 * @description
 */
@Configuration
public class MyWebConfig implements WebMvcConfigurer {

    @Autowired
    @Qualifier("loginInterceptor")
    private HandlerInterceptor loginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        InterceptorRegistration registration = registry.addInterceptor(loginInterceptor);
        // 拦截所有请求
        registration.addPathPatterns("/**");
        // 放行请求
        registration.excludePathPatterns(
                "/login",
                "/email/**",
                "/resetPassword",
                "/register",
                "/forgotPassword",
                "/user/logout",
                "/captcha",
                "/admin/**",
                "/layui/**",
                "/css/**",
                "/js/**",
                "/images/**",
                "/lib/**"
        );
    }
}
